package gui.panel;

import enums.ExtensionEnum;
import enums.PremisaTypeEnum;
import j_util.Utiles;
import model.Polisilogismo;
import model.Premisa;
import model.Sylogism;

import javax.swing.*;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * Extension de JPanel, referido a la funcionalidad y visualizacion de polisilogismo.
 * Codigo poco mantenible, se considera su eliminacion en algun momento;
 * @author Jose Martin Rozanec;
 * @deprecated;
 */
public class PolisilogismoPanel extends JPanel {

    private javax.swing.JButton ascendenteButton;
    private javax.swing.JPanel bottomPanel;
    private javax.swing.JComboBox combo1;
    private javax.swing.JComboBox combo2;
    private javax.swing.JComboBox combo3;
    private javax.swing.JButton completeButton;
    private javax.swing.JLabel completeLabel;
    private javax.swing.JTextField conclusionField;
    private javax.swing.JLabel conclusionLabel;
    private javax.swing.JLabel convertirEnLabel;
    private javax.swing.JPanel cuadroPanel;
    private javax.swing.JButton descendenteButton;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JTextField premisaMayorField;
    private javax.swing.JLabel premisaMayorLabel;
    private javax.swing.JTextField premisaMenorField;
    private javax.swing.JLabel premisaMenorLabel;
    private javax.swing.JButton resetButton;
    private javax.swing.JLabel terminoMayorLabel;
    private javax.swing.JLabel terminoMedioLabel;
    private javax.swing.JLabel terminoMenorLabel;
    private javax.swing.JTextArea textArea;
    private javax.swing.JLabel validLabel;
    private javax.swing.JPanel analisisPanel;
    private javax.swing.JTextArea analisisTextArea;
    private JScrollPane jScrollPane2;
    private int state = 0;//-1 if descendente, 1 if ascendente

    private Sylogism sylogism;
    private Polisilogismo polisilogismo;

    public PolisilogismoPanel() {
        this.polisilogismo = new Polisilogismo();
        sylogism = new Sylogism();
        initComponents();
    }

    private void initComponents() {
        mainPanel = new javax.swing.JPanel();
        cuadroPanel = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        premisaMayorField = new javax.swing.JTextField();
        premisaMayorLabel = new javax.swing.JLabel();
        convertirEnLabel = new javax.swing.JLabel();
        combo1 = new javax.swing.JComboBox();
        premisaMenorLabel = new javax.swing.JLabel();
        premisaMenorField = new javax.swing.JTextField();
        combo2 = new javax.swing.JComboBox();
        jSeparator1 = new javax.swing.JSeparator();
        conclusionLabel = new javax.swing.JLabel();
        conclusionField = new javax.swing.JTextField();
        combo3 = new javax.swing.JComboBox();
        ascendenteButton = new javax.swing.JButton();
        descendenteButton = new javax.swing.JButton();
        resetButton = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        completeLabel = new javax.swing.JLabel();
        validLabel = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        terminoMayorLabel = new javax.swing.JLabel();
        terminoMedioLabel = new javax.swing.JLabel();
        terminoMenorLabel = new javax.swing.JLabel();
        completeButton = new javax.swing.JButton();
        bottomPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        textArea = new javax.swing.JTextArea();
        analisisPanel = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        analisisTextArea = new javax.swing.JTextArea();


        mainPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(204, 204, 204), 1, true), "Polisilogismo"));

        cuadroPanel.setBackground(new java.awt.Color(255, 255, 255));
        cuadroPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(204, 204, 204), 1, true), "Silogismo"));

        premisaMayorLabel.setText("Premisa mayor");

        convertirEnLabel.setText("Convertir en");

        combo1.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"A", "E", "I", "O"}));
        combo1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                comboConvertOrComplete(PremisaTypeEnum.FIRST, combo1.getSelectedIndex());
            }
        });

        premisaMenorLabel.setText("Premisa menor");

        combo2.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"A", "E", "I", "O"}));
        combo2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                comboConvertOrComplete(PremisaTypeEnum.FIRST, combo2.getSelectedIndex());
            }
        });

        jSeparator1.setForeground(new java.awt.Color(0, 0, 0));

        conclusionLabel.setText("Conclusion");

        combo3.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"A", "E", "I", "O"}));
        combo3.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                comboConvertOrComplete(PremisaTypeEnum.CONCLUSION, combo3.getSelectedIndex());

            }
        });

        premisaMayorField.addCaretListener(new CaretListener() {
            public void caretUpdate(CaretEvent e) {
                analize();
                if (Premisa.isComplete(premisaMayorField.getText())) {
                    sylogism.setPremisa(new Premisa(premisaMayorField.getText()), PremisaTypeEnum.FIRST);
                    premisaMayorField.setForeground(new Color(0, 0, 0));
                } else {
                    sylogism.setPremisa(null, PremisaTypeEnum.FIRST);
                    premisaMayorField.setForeground(new Color(255, 0, 0));
                }
            }
        });

        premisaMenorField.addCaretListener(new CaretListener() {
            public void caretUpdate(CaretEvent e) {
                analize();
                if (Premisa.isComplete(premisaMenorField.getText())) {
                    sylogism.setPremisa(new Premisa(premisaMenorField.getText()), PremisaTypeEnum.SECOND);
                    premisaMenorField.setForeground(new Color(0, 0, 0));
                } else {
                    sylogism.setPremisa(null, PremisaTypeEnum.SECOND);
                    premisaMenorField.setForeground(new Color(255, 0, 0));
                }
            }
        });

        conclusionField.addCaretListener(new CaretListener() {
            public void caretUpdate(CaretEvent e) {
                analize();
                if (Premisa.isComplete(conclusionField.getText())) {
                    sylogism.setPremisa(new Premisa(conclusionField.getText()), PremisaTypeEnum.CONCLUSION);
                    conclusionField.setForeground(new Color(0, 0, 0));
                } else {
                    sylogism.setPremisa(null, PremisaTypeEnum.CONCLUSION);
                    conclusionField.setForeground(new Color(255, 0, 0));
                }
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(conclusionLabel)
                                .addContainerGap())
                        .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(premisaMenorLabel)
                                .addContainerGap())
                        .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(premisaMayorLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 437, Short.MAX_VALUE)
                                .addComponent(convertirEnLabel)
                                .addGap(34, 34, 34))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(conclusionField, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(premisaMenorField, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(premisaMayorField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 492, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(combo1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(combo2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(combo3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(35, Short.MAX_VALUE))))
        );
        jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(premisaMayorLabel)
                                .addComponent(convertirEnLabel))
                        .addGap(5, 5, 5)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(premisaMayorField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(combo1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(premisaMenorLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(premisaMenorField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(combo2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(conclusionLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(conclusionField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(combo3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(27, Short.MAX_VALUE))
        );

        ascendenteButton.setText("Ascendente");
        ascendenteButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (sylogism.validate()) {
                    if (polisilogismo.initialSylogismWasSet()) {
                        if (state == 1) {
                            polisilogismo.addAscendente(sylogism.getPremisa(PremisaTypeEnum.FIRST),
                                    sylogism.getPremisa(PremisaTypeEnum.SECOND));
                        }
                        if (state == -1) {
                            polisilogismo.addDescendente(sylogism.getPremisa(PremisaTypeEnum.SECOND),
                                    sylogism.getPremisa(PremisaTypeEnum.CONCLUSION));
                        }
                    } else {
                        polisilogismo.setInitialSylogism(sylogism);
                    }
                    state = 1;
                    setAscendenteTextField();
//                    textArea.setText(polisilogismo.toString());
                } else {
                    JOptionPane.showMessageDialog(PolisilogismoPanel.this, "El silogismo propuesto no es valido. No sera agregado al polisilogismo.", "", JOptionPane.WARNING_MESSAGE);
                    if (polisilogismo.initialSylogismWasSet()) {
                        setAscendenteTextField();
                    }
                }
            }
        });

        descendenteButton.setText("Descendente");
        descendenteButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (sylogism.validate()) {
                    if (polisilogismo.initialSylogismWasSet()) {
                        if (state == 1) {
                            polisilogismo.addAscendente(sylogism.getPremisa(PremisaTypeEnum.FIRST),
                                    sylogism.getPremisa(PremisaTypeEnum.SECOND));
                        }
                        if (state == -1) {
                            polisilogismo.addDescendente(sylogism.getPremisa(PremisaTypeEnum.SECOND),
                                    sylogism.getPremisa(PremisaTypeEnum.CONCLUSION));
                        }
                    } else {
                        polisilogismo.setInitialSylogism(sylogism);
                    }
                    textArea.setText(polisilogismo.toString());
                    setDescendenteTextField();
                } else {
                    JOptionPane.showMessageDialog(PolisilogismoPanel.this, "El silogismo propuesto no es valido. No sera agregado al polisilogismo.", "", JOptionPane.WARNING_MESSAGE);
                    if (polisilogismo.initialSylogismWasSet()) {
                        setDescendenteTextField();
                    }
                }
            }
        });

        resetButton.setText("Resetear");
        resetButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                resetAll();
            }
        });

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(204, 204, 204), 1, true), "Estado"));

        completeLabel.setIcon(Utiles.createImageIcon("/gui/images/button_incompleto.png"));

        validLabel.setIcon(Utiles.createImageIcon("/gui/images/button_invalido.png"));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(completeLabel)
                        .addGap(18, 18, 18)
                        .addComponent(validLabel)
                        .addContainerGap(22, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(validLabel)
                                .addComponent(completeLabel))
                        .addContainerGap(47, Short.MAX_VALUE))
        );

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(204, 204, 204), 1, true), "Terminos"));

        terminoMayorLabel.setText("Termino mayor:");

        terminoMedioLabel.setText("Termino medio:");

        terminoMenorLabel.setText("Termino menor:");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(terminoMayorLabel)
                                .addComponent(terminoMenorLabel)
                                .addComponent(terminoMedioLabel))
                        .addContainerGap(279, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(terminoMayorLabel)
                        .addGap(36, 36, 36)
                        .addComponent(terminoMedioLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)
                        .addComponent(terminoMenorLabel)
                        .addGap(26, 26, 26))
        );

        completeButton.setText("Completar");
        completeButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                sylogism.complete();
                setSylogism(sylogism);
            }
        });

        javax.swing.GroupLayout analisisPanelLayout = new javax.swing.GroupLayout(analisisPanel);
        analisisPanel.setBackground(Color.WHITE);
        analisisPanel.setLayout(analisisPanelLayout);
        analisisPanelLayout.setHorizontalGroup(
                analisisPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 628, Short.MAX_VALUE)
        );
        analisisPanelLayout.setVerticalGroup(
                analisisPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout cuadroPanelLayout = new javax.swing.GroupLayout(cuadroPanel);
        cuadroPanel.setLayout(cuadroPanelLayout);
        cuadroPanelLayout.setHorizontalGroup(
                cuadroPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, cuadroPanelLayout.createSequentialGroup()
                        .addGroup(cuadroPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, cuadroPanelLayout.createSequentialGroup()
                                        .addContainerGap()
                                        .addComponent(analisisPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, cuadroPanelLayout.createSequentialGroup()
                                        .addContainerGap()
                                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(cuadroPanelLayout.createSequentialGroup()
                                .addGap(43, 43, 43)
                                .addComponent(ascendenteButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 108, Short.MAX_VALUE)
                                .addComponent(descendenteButton)
                                .addGap(80, 80, 80)
                                .addComponent(completeButton)
                                .addGap(79, 79, 79)
                                .addComponent(resetButton)))
                        .addContainerGap())
        );
        cuadroPanelLayout.setVerticalGroup(
                cuadroPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(cuadroPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(cuadroPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(ascendenteButton)
                                .addComponent(descendenteButton)
                                .addComponent(completeButton)
                                .addComponent(resetButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(analisisPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
                mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(mainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(cuadroPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 665, Short.MAX_VALUE)
                        .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
                mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(cuadroPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        bottomPanel.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(204, 204, 204), 1, true), "Polisilogismo"), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED)));

        textArea.setColumns(20);
        textArea.setEditable(false);
        textArea.setRows(5);
        jScrollPane1.setViewportView(textArea);

        analisisPanel.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(204, 204, 204), 1, true), "Analisis del silogismo actual"), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED)));

        analisisTextArea.setColumns(20);
        analisisTextArea.setRows(5);
        analisisTextArea.setEditable(false);
        jScrollPane2.setViewportView(analisisTextArea);

        javax.swing.GroupLayout bottomPanelLayout = new javax.swing.GroupLayout(bottomPanel);
        bottomPanel.setLayout(bottomPanelLayout);
        bottomPanelLayout.setHorizontalGroup(
                bottomPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 681, Short.MAX_VALUE)
        );
        bottomPanelLayout.setVerticalGroup(
                bottomPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(bottomPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(mainPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap(12, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                        .addComponent(mainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bottomPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
        );
    }

    private void reset() {
        premisaMayorField.setText("");
        premisaMenorField.setText("");
        conclusionField.setText("");
        sylogism = new Sylogism();
    }

    private void resetAll() {
        reset();
        premisaMayorField.setEditable(true);
        conclusionField.setEditable(true);
        polisilogismo = new Polisilogismo();
        analize();
    }

    public void comboConvertOrComplete(PremisaTypeEnum premisaTypeEnum, int selectedIndex) {
        if (sylogism.getPremisa(premisaTypeEnum) != null) {
            switch (selectedIndex) {
                case 0://A
                    sylogism.getPremisa(premisaTypeEnum).convert(ExtensionEnum.A);
                    break;
                case 1://E
                    sylogism.getPremisa(premisaTypeEnum).convert(ExtensionEnum.E);
                    break;
                case 2://I
                    sylogism.getPremisa(premisaTypeEnum).convert(ExtensionEnum.I);
                    break;
                case 3://O
                    sylogism.getPremisa(premisaTypeEnum).convert(ExtensionEnum.O);
                    break;
                case 4://todo getRandomPremisa=>permite completar una premisa en particular
                    break;
            }
            switch (premisaTypeEnum) {
                case FIRST:
                    premisaMayorField.setText(sylogism.getPremisa(premisaTypeEnum).toString());
                    break;
                case SECOND:
                    premisaMenorField.setText(sylogism.getPremisa(premisaTypeEnum).toString());
                    break;
                case CONCLUSION:
                    conclusionField.setText(sylogism.getPremisa(premisaTypeEnum).toString());
                    break;
            }
        }
//        setPropertiesOrSuggestions();
    }

    public void setPolisilogismo(Polisilogismo polisilogismo) {
        sylogism = new Sylogism();
        this.polisilogismo = polisilogismo;
        analize();
    }

    public void setSylogism(Sylogism sylogism) {
        this.sylogism = sylogism;
        if (sylogism.getPremisa(PremisaTypeEnum.FIRST) != null) {
            premisaMayorField.setText(sylogism.getPremisa(PremisaTypeEnum.FIRST).toString());
        }
        if (sylogism.getPremisa(PremisaTypeEnum.SECOND) != null) {
            premisaMenorField.setText(sylogism.getPremisa(PremisaTypeEnum.SECOND).toString());
        }
        if (sylogism.getPremisa(PremisaTypeEnum.CONCLUSION) != null) {
            conclusionField.setText(sylogism.getPremisa(PremisaTypeEnum.CONCLUSION).toString());
        }
        analize();
    }

    private void analize() {
        manageCompleteButton();
        textArea.setText(polisilogismo.toString());
        StringBuffer textAreaText = new StringBuffer();
        if (!sylogism.isComplete()) {
            textAreaText.append("Sugerencias:\n");
            textAreaText.append(sylogism.getPremisaSuggestion());
            textAreaText.append("\n-------------------------------------------------------------------\n");
        }
        setValidCompleteImages();
        textAreaText.append("Terminos:\n");
        textAreaText.append(getTerminos());//en su lugar se deberia setear los terminos en los labels
        textAreaText.append("\n-------------------------------------------------------------------\n");
        textAreaText.append("Analisis:\n");
        textAreaText.append(sylogism.analize());
        analisisTextArea.setText(textAreaText.toString());
    }

    private void setAscendenteTextField() {
        reset();
        conclusionField.setText(polisilogismo.getFirstSylogism().getPremisa(PremisaTypeEnum.FIRST).toString());
        sylogism.setPremisa(polisilogismo.getFirstSylogism().getPremisa(PremisaTypeEnum.FIRST), PremisaTypeEnum.CONCLUSION);
        conclusionField.setEditable(false);
        combo3.setEnabled(false);
        premisaMayorField.setEditable(true);
        combo1.setEnabled(true);
        premisaMenorField.setEditable(true);
        analize();
    }

    private void setDescendenteTextField() {
        reset();
        premisaMayorField.setText(polisilogismo.getLastSylogism().getPremisa(PremisaTypeEnum.CONCLUSION).toString());
        sylogism.setPremisa(polisilogismo.getFirstSylogism().getPremisa(PremisaTypeEnum.CONCLUSION), PremisaTypeEnum.FIRST);
        conclusionField.setEditable(true);
        premisaMayorField.setEditable(false);
        combo1.setEnabled(false);
        premisaMenorField.setEditable(true);
        combo3.setEnabled(true);
        analize();
    }

    private String getTerminos() {
        return "\tTermino mayor: " + sylogism.getTerminoMayor() + "\n" +
                "\tTermino medio: " + sylogism.getTerminoMedio() + "\n" +
                "\tTermino menor: " + sylogism.getTerminoMenor();
    }

    private void manageCompleteButton() {
        int i = 0;
        if (!sylogism.getTerminoMayor().equals("")) {
            i++;
        }
        if (!sylogism.getTerminoMedio().equals("")) {
            i++;
        }
        if (!sylogism.getTerminoMenor().equals("")) {
            i++;
        }
        if (i >= 2) {
            completeButton.setEnabled(true);
        } else {
            completeButton.setEnabled(false);
        }
    }

    private void setValidCompleteImages() {
        if (!sylogism.isComplete()) {
            completeLabel = new JLabel(Utiles.createImageIcon("/gui/images/button_incompleto.png"));
        } else {
            completeLabel = new JLabel(Utiles.createImageIcon("/gui/images/button_completo.png"));
        }
        if (sylogism.validate()) {
            validLabel.setIcon(Utiles.createImageIcon("/gui/images/button_valido.png"));
        } else {
            validLabel = new JLabel(Utiles.createImageIcon("/gui/images/button_invalido.png"));
        }
    }
}